package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 配置信息实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysConfigDO extends BaseUpdEntity<Long> {

    /** ID,Long */
    @NotNull(message = "ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long id;

    /** 参数类型,程序编码使用,String */
    @NotNull(message = "参数类型,程序编码使用,不能为空", groups = InsertGroup.class)
    @Size(max = 32,message = "参数类型,程序编码使用,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String paramType;

    /** 类型名称,String */
    @Size(max = 64,message = "类型名称,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String typeName;

    /** 参数编码,程序编码使用,String */
    @NotNull(message = "参数编码,程序编码使用,不能为空", groups = InsertGroup.class)
    @Size(max = 32,message = "参数编码,程序编码使用,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String paramKey;

    /** 参数名称，String */
    @NotNull(message = "参数名称,不能为空", groups = InsertGroup.class)
    @Size(max = 64,message = "参数名称,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String paramName;

    /** 参数值，String */
    @Size(max = 256,message = "参数值,最大长度256个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String paramValue;

    /** 参数类型, 枚举类型: DataTypeEnum，Integer */
    private Integer dataType;

    /** 选择标识, 枚举类型: ChooseFlagEnum，Integer */
    private Integer chooseFlag;

    /** 数据来源, 枚举类型: ConfigSourceEnum，Integer */
    private Integer sourceType;

    /** 字典中的param_type值，String */
    @Size(max = 32,message = "字典中的param_type值,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String sourceDictType;

    /** ID-NAME接口的地址，String */
    @Size(max = 256,message = "ID-NAME接口的地址,最大长度256个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String sourceIdName;

    /** 固定值可选项，数组格式：[1,2,3]，String */
    @Size(max = 256,message = "固定值可选项，数组格式：[1,2,3],最大长度256个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String sourceItems;

    /** 排序号，Integer */
    private Integer sortNo;

    /** 备注说明，String */
    @Size(max = 512,message = "备注说明,最大长度512个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String description;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return id;
    }

    @Override
    public void checkBeforeInsert() {
        if (StringExtUtils.isAnyEmpty(paramType)) {
            throw new VerifyFailException("SysConfigDO.paramType 必须非空");
        }
        if (StringExtUtils.isAnyEmpty(paramKey)) {
            throw new VerifyFailException("SysConfigDO.paramKey 必须非空");
        }
        if (StringExtUtils.isAnyEmpty(paramName)) {
            throw new VerifyFailException("SysConfigDO.paramName 必须非空");
        }
    }

    @Override
    public String toString() {
        return "id=" + id +
                ", paramType='" + paramType + "'" +
                ", typeName='" + typeName + "'" +
                ", paramKey='" + paramKey + "'" +
                ", paramName='" + paramName + "'" +
                ", paramValue='" + paramValue + "'" +
                ", dataType=" + dataType +
                ", chooseFlag=" + chooseFlag +
                ", sourceType=" + sourceType +
                ", sourceDictType='" + sourceDictType + "'" +
                ", sourceIdName='" + sourceIdName + "'" +
                ", sourceItems='" + sourceItems + "'" +
                ", sortNo=" + sortNo +
                ", description='" + description + "'" +
                ", " + super.toString();
    }

}
